home *** CD-ROM | disk | FTP | other *** search
- ;unsigned short range_count(strg,char_1,char_2);
- ; unsigned char *strg,char_1,char_2;
-
- EXTRN _memory_model:byte
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _range_count
- _range_count proc near
- push bp ;
- mov bp,sp ;set up stack frame
- push si ;
- push ds ;
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: cmp _memory_model,2 ;data near or far?
- jb L0 ;jump if near
- lds si,dword ptr[bp+4] ;DS:SI pts to Strg
- inc bp ;add 2 to BP since dword ptr
- inc bp ;
- jmp short L00 ;
- L0: mov si,[bp+4] ;near case
- L00: sub dx,dx ;clear DX for tally
- mov ah,[bp+6] ;get one end of range
- mov al,[bp+8] ;get other end of range
- cmp ah,al ;compare the values
- jae L1 ;jump if AH >= AL
- xchg ah,al ;else, high value to AH
- L1: cmp byte ptr[si],0 ;test for null string
- je L4 ;quit if null
- L2: mov bl,[si] ;get character
- inc si ;forward ptr for next time
- cmp bl,0 ;end of string?
- je L4 ;
- cmp bl,ah ;test against high char
- ja L3 ;skip ahead if above
- cmp bl,al ;test against low char
- jb L3 ;skip ahead if below
- inc dx ;increment counter
- L3: jmp short L2 ;go test next char
- L4: mov ax,dx ;set value for return
- pop ds ;
- pop si ;
- pop bp ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _range_count ENDP
- _TEXT ENDS
- END